<script lang="ts" setup>
import { login } from "../../../api/";
import { useTokenStore } from "../../../store/";
const router = useRouter();
const form = reactive({
  email: "",
  password: "",
});
const store = useTokenStore();
const loginUser = async () => {
  const data = await login(form);
  if (data.data) {
    console.log(data);
    store.setToken(data.data);
    ElMessage({
      message: "登录成功",
      type: "success",
    });
    router.push("/");
  } else {
    console.log("数据获取失败");
    ElMessage({
      message: "登录失败",
      type: "error",
    });
  }
};
</script>
<template>
  <div class="flex justify-center h-[100vh] items-center flex-col">
    <div class="mb-5">登录页面</div>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="邮箱地址">
        <el-input v-model="form.email" placeholder="请输入邮箱地址" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="loginUser" class="m-auto"
          >登录</el-button
        >
        <div class="ml-20">
          未注册,去
          <router-link to="/registry"> 注册 </router-link>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
